package com.sun.officeoa.dao;

import com.sun.officeoa.bean.Counter;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class CountDao {
    @Resource
    private JdbcTemplate jdbcTemplate;

    public int getCount() {
        List<Counter> coutter = null;
        String sql = "SELECT * from counter";
        RowMapper<Counter> rowMapper = new BeanPropertyRowMapper<Counter>(Counter.class);
        coutter = jdbcTemplate.query(sql,rowMapper);
        return (coutter != null && coutter.size() > 0) ? coutter.size() : 0;
    }

    public int updateCount(int count) {
            String sql = "UPDATE counter SET visitcount=?";
            return jdbcTemplate.update(sql,count);

    }
}